$(document).ready(function() {	
	$.ajax({
  		type: "post",
 		url: "hmk/findExpertArea_findAll.action",
  		success:function(data){
  			$.each(data.expareaList,function(i,n){
  				$("<option value="+n.expareaId+">"+n.expareaName+"</option>").appendTo('#areaID');
			});
  		}
	});
	
	$.ajax({
  		type: "post",
 		url: "hmk/getWukuType_getWukuType.action",
  		success:function(data){
  			$.each(data.typeList,function(i,n){
  				$("<option value="+n.tpyeId+">"+n.tpyeName+"</option>").appendTo('#typeID');
			});
  		}
	});
	getCurrent(1,10);

	$('#FIND_EXP_TOP').click(function(){		
		var typeID=$('#typeID  option:selected').val();
		var expName=$('#expNameID').val();
		var areaID=$('#areaID  option:selected').val();
		//var expRusume=$('#expRusumeID').val();
		
		//alert(eId+eventTimeStart+eventTimeEnd);
		//$("#eventTable").fadeIn("fast");
		//$("#loadingEvent").show();
		//expRusume1:expRusume
		//$('#mainFrame',window.parent.document).attr('src','hmk/ExpertMain.jsp');
		
		$.ajax({
  			type: "post",
 			url: "hmk/findSomeExpert_findExpertList.action",
 			data:{
 				  typeID1:typeID,areaID1:areaID,expName1:expName
 				 },
  			success:showData
		});
		
	});
	
	$('#firstPage').click(function(){		
		var page=1;
		var maxRow=$("#maxRow").text();
		var typeID=$(window.parent.frames["topFrame"].document).find('#typeID  option:selected').val();
		var expName=$(window.parent.frames["topFrame"].document).find('#expNameID').val();
		var areaID=$(window.parent.frames["topFrame"].document).find('#areaID  option:selected').val();
		//var expRusume=$(window.parent.frames["topFrame"].document).find('#expRusumeID').val();
		
		//alert(eId+eventTimeStart+eventTimeEnd);
		//$("#eventTable").fadeIn("fast");
		//$("#loadingEvent").show();
		//expRusume1:expRusume,
		$.ajax({
  			type: "post",
 			url: "hmk/findSomeExpert_findExpertList.action",
 			data:{
 				  typeID1:typeID,areaID1:areaID,expName1:expName,
 				  page:page,maxRow:maxRow
 				 },
  			success:showData
		});
		
	});
	
	$('#prePage').click(function(){		
		var page=$("#page").text();
		page=(parseInt(page)-1);
		var maxRow=$("#maxRow").text();
		var typeID=$(window.parent.frames["topFrame"].document).find('#typeID  option:selected').val();
		var expName=$(window.parent.frames["topFrame"].document).find('#expNameID').val();
		var areaID=$(window.parent.frames["topFrame"].document).find('#areaID  option:selected').val();
		//var expRusume=$(window.parent.frames["topFrame"].document).find('#expRusumeID').val();
		
		//alert(eId+eventTimeStart+eventTimeEnd);
		//$("#eventTable").fadeIn("fast");
		//$("#loadingEvent").show();
		$.ajax({
  			type: "post",
 			url: "hmk/findSomeExpert_findExpertList.action",
 			data:{
 				  typeID1:typeID,areaID1:areaID,expName1:expName,
 				  page:page,maxRow:maxRow
 				 },
  			success:showData
		});
		
	});
	
	$('#nextPage').click(function(){		
		var page=$("#page").text();
		page=(parseInt(page)+1);
		var maxRow=$("#maxRow").text();
		var typeID=$(window.parent.frames["topFrame"].document).find('#typeID  option:selected').val();
		var expName=$(window.parent.frames["topFrame"].document).find('#expNameID').val();
		var areaID=$(window.parent.frames["topFrame"].document).find('#areaID  option:selected').val();
		//var expRusume=$(window.parent.frames["topFrame"].document).find('#expRusumeID').val();
		
		//alert(eId+eventTimeStart+eventTimeEnd);
		//$("#eventTable").fadeIn("fast");
		//$("#loadingEvent").show();
		$.ajax({
  			type: "post",
 			url: "hmk/findSomeExpert_findExpertList.action",
 			data:{
 				  typeID1:typeID,areaID1:areaID,expName1:expName,
 				  page:page,maxRow:maxRow
 				 },
  			success:showData
		});
		
	});
	
	$('#lastPage').click(function(){		
		var page=$("#pageCount").text();
		var maxRow=$("#maxRow").text();
		var typeID=$(window.parent.frames["topFrame"].document).find('#typeID  option:selected').val();
		var expName=$(window.parent.frames["topFrame"].document).find('#expNameID').val();
		var areaID=$(window.parent.frames["topFrame"].document).find('#areaID  option:selected').val();
		//var expRusume=$(window.parent.frames["topFrame"].document).find('#expRusumeID').val();
		
		//alert(eId+eventTimeStart+eventTimeEnd);
		//$("#eventTable").fadeIn("fast");
		//$("#loadingEvent").show();
		$.ajax({
  			type: "post",
 			url: "hmk/findSomeExpert_findExpertList.action",
 			data:{
 				  typeID1:typeID,areaID1:areaID,expName1:expName,
 				  page:page,maxRow:maxRow
 				 },
  			success:showData
		});
		
	});
	
	$('#jumpPage').click(function(){		
		var pageCount=$("#pageCount").text();
		var maxRow=$("#maxRow").text();
		var typeID=$(window.parent.frames["topFrame"].document).find('#typeID  option:selected').val();
		var expName=$(window.parent.frames["topFrame"].document).find('#expNameID').val();
		var areaID=$(window.parent.frames["topFrame"].document).find('#areaID  option:selected').val();
		//var expRusume=$(window.parent.frames["topFrame"].document).find('#expRusumeID').val();
		
		//alert(eId+eventTimeStart+eventTimeEnd);
		//$("#eventTable").fadeIn("fast");
		//$("#loadingEvent").show();
		var page=$("#jump").val();
		if(page>pageCount){
			alert("jumpPage > pageCount");
			return;
		}
		$.ajax({
  			type: "post",
 			url: "hmk/findSomeExpert_findExpertList.action",
 			data:{
 				  typeID1:typeID,areaID1:areaID,expName1:expName,
 				  page:page,maxRow:maxRow
 				 },
  			success:showData
		});
		
	});

});

function getCurrent(page1,maxRow1){
		var page=page1;
		var maxRow=maxRow1;
		var typeID=$(window.parent.frames["topFrame"].document).find('#typeID  option:selected').val();
		var expName=$(window.parent.frames["topFrame"].document).find('#expNameID').val();
		var areaID=$(window.parent.frames["topFrame"].document).find('#areaID  option:selected').val();
		//var expRusume=$(window.parent.frames["topFrame"].document).find('#expRusumeID').val();
		
		//alert(eId+eventTimeStart+eventTimeEnd);
		//$("#eventTable").fadeIn("fast");
		//$("#loadingEvent").show();
		//expRusume1:expRusume,
		$.ajax({
  			type: "post",
 			url: "hmk/findSomeExpert_findExpertList.action",
 			data:{
 				  typeID1:typeID,areaID1:areaID,expName1:expName,
 				  page:page,maxRow:maxRow
 				 },
  			success:showData
		});
}

function getExpertDetail(v){
	var content = $(v).next().text();
	//alert(content);
	//window.location.replace("hmk/ExpertDetail.jsp");
	window.location.href="/ag/hmk/findOneExpert_findOneExpert.action?expertID="+content+"&findType1=1";
	/*
	var url = 'hmk/findOneTeam_getOneTeam.action';
	var params = {
			teamID:content
	}; 
	jQuery.post(url, params, teamData, 'json'); */
}

	function showData(data){
		$('#expertBody').empty();	
		if(data.pageUtil.list.length==0){
			//$("#loadingEvent").hide();
			//$("#noneEvent").show();
		}else{
			//$("#listEvent").hide();
			//$("#noneEvent").hide();
		   // $("#loadingEvent").hide();
		   //alert("to html");
		    $.each(data.pageUtil.list,function(i,n){
		    	//alert(n.tbType.tpyeName);
		    	//n.expBirthday
				var sex ="男";
				if(n.expSex=='0') sex="女";
				fillDataToHtml(n.expId,n.tbType.tpyeName,n.tbExpertArea.expareaName,n.expName,
						  sex,n.expMobile,n.expUnit,n.expTitle,n.expPost);
						  
						  
		  	});
		
		$('#total').text(data.pageUtil.total);
		$('#page').text(data.pageUtil.page);
		$('#pageCount').text(Math.ceil(data.pageUtil.total/10));
		$('#maxRow').text(data.pageUtil.maxRow);
		}
	}
	
	function fillDataToHtml(eid,etype,earea,ename,esex,ephone,eunit,etitle,epost){
		// strHtml+=ebirthday.replace(/T/," ")+"</div></td>";
		var strHtml="<tr>";
		strHtml+="<td id='"+eid+"'><div><input name='read' type='radio' /></div></td>";
		strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=etype+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=earea+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=ename+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=esex+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=ephone+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=eunit+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=etitle+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=epost+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+="参与了xx事件处置"+"</div></td>";
        strHtml+="</tr>";
        $('#expertBody').append(strHtml);
        var expid = '#'+eid;
        $(expid).click(function () {
		//var eid=$("#eid",window.parent.frames['mainFrame'].document).text();
		var strHTML="<div id='smsp' class='faqbg'></div>";
			strHTML+="<div id='subsmsp' class='faqdiv' style='display:none'>";
			strHTML+="<h2>通知专家<span class='close'>关闭</span></h2>";
			strHTML+="<div class='subArea'>受理单号：<span style='color:red;font-size:18'>"+eid+"</span>    事件名称：药害事件1</div>";
			strHTML+="<div class='subArea'>姓名：<span id='expName'>专家1</span></div>";
			strHTML+="<div class='subArea'>最迟建议时间：<input type='text' /></div>";
			strHTML+="<div class='subArea'><span style='float: left;'>通知内容：</span><textarea id='smsContent' style='width:320;height:100'>现有药害事件1，受理单号："+eid+",请尽快登陆系统添加建议。</textarea></div>";
			strHTML+="<div ><span style='padding-left:290'><button id='submit' class='submit'>通知</button></span>";
			strHTML+=" <span style='padding-left:10'><button class='submit close'>取 消</button></span></div><br />";
			strHTML+="</div>"
			$("body",window.parent.frames['mainFrame'].document).append(strHTML);
			$("#smsp",window.parent.frames['mainFrame'].document).css({display:"block",height:$(window.parent.frames['mainFrame'].document).height()});
			$("#subsmsp",window.parent.frames['mainFrame'].document).css("display","block");
			window.parent.frames['mainFrame'].document.documentElement.scrollTop=0;
			$(".close",window.parent.frames['mainFrame'].document).click(function(){
				$("#smsp",window.parent.frames['mainFrame'].document).remove();
	  			$("#subsmsp",window.parent.frames['mainFrame'].document).remove();
			});
			$("#submit",window.parent.frames['mainFrame'].document).click(function(){
				var expName = $("#expName").text();
				var sms = $("#smsContent").text();
				alert("已成功通知"+expName);
				$("#smsp",window.parent.frames['mainFrame'].document).remove();
	  			$("#subsmsp",window.parent.frames['mainFrame'].document).remove();
	  			var strHtml="<tr>";
	  			strHtml+="<td ><div>公共卫生类</div></td>";
	  			strHtml+="<td ><div>医学技术领域</div></td>";
	  			strHtml+="<td ><div>"+expName+"</div></td>";
	  			strHtml+="<td ><div>13640851886</div></td>";
	  			strHtml+="<td ><div>参与了xx事件处置</div></td>";
        		strHtml+="</tr>";
        		$('#exp_notify').append(strHtml);
				//window.location.href="event_man.jsp";
			});
	});
	}